﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.CustomerManage.PickupPhoto
{
    public partial class FrmSetShop : Form
    {
        //属性
        public FrmDisposeMain frm;
        public DataTable ShopDt;                    //商户的集合
        public int ShopId;                          //选中的商户Id

        public FrmSetShop()
        {
            InitializeComponent();
        }

        private void FrmSetShop_Load(object sender, EventArgs e)
        {
            lbShop.DisplayMember = "ShopName";
            lbShop.ValueMember = "ShopId";
            lbShop.DataSource = ShopDt;
            lbShop.SelectedValue = ShopId;
            btnOk.Focus();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            DataRowView item = (DataRowView)lbShop.SelectedItem;
            string shopName = item["ShopName"].ToString();
            int shopId = Convert.ToInt32(item["ShopId"]);
            frm.SelectedShopName = shopName;
            frm.SelectedShopId = shopId;
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //助记码筛选
        private void txtShopZJM_TextChanged(object sender, EventArgs e)
        {
            DataTable newDt = ShopDt.Clone();
            string code = txtShopZJM.Text.Trim();
            DataRow[] fr = ShopDt.Select("ZJCode like '%" + code + "%'");
            foreach (DataRow r in fr)
            {
                DataRow nr = newDt.NewRow();
                nr.ItemArray = r.ItemArray;
                newDt.Rows.Add(nr);
            }
            DataRow[] fr2 = ShopDt.Select("ShopName like '%" + code + "%'");
            foreach (DataRow r in fr2)
            {
                DataRow[] rows= newDt.Select("ShopName = '" + r.ItemArray[1] + "'");
                if (rows.Count() == 0)
                {
                    DataRow nr = newDt.NewRow();
                    nr.ItemArray = r.ItemArray;
                    newDt.Rows.Add(nr);
                }
            }
            lbShop.DisplayMember = "ShopName";
            lbShop.ValueMember = "ShopId";
            lbShop.DataSource = newDt;
        }
    }
}
